<template>
	<view class="registerPage">
		<image src="/pages-landlord/static/images/reset-bg.png" class="pageBg"></image>
		<view class="title">重置密码</view>
		<view class="tips">请输入包含英文或数字的8位密码</view>
		<!-- 登录表单 -->
		<view class="loginForm">
			<view class="formContent">
				<view class="input">
					<view class="input-label">手机号</view>
					<view class="input-value">{{mobile}}</view>
					<!-- <u-input placeholder="请输入手机号" border="none" v-model="mobile" ></u-input> -->
				</view>
				<view class="input">
					<view class="input-label">验证码</view>
					<u-input placeholder="请输入验证码" border="none" v-model="verification">
						<template slot="suffix">
							<u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
							<text @tap="getVerificationCode" class="text">{{codeTips}}</text>
						</template>
					</u-input>
				</view>
				<view class="input">
					<view class="input-label">新密码</view>
					<u-input placeholder="请输入新密码" password="password" border="none" v-model="password"></u-input>
				</view>
				<view class="input">
					<view class="input-label">确认密码</view>
					<u-input placeholder="请输入确认密码" password="password" border="none"
						v-model="password_confirm"></u-input>
				</view>
			</view>

			<view class="loginButton" @click="$u.throttle(userRegister, 5000)">确定</view>
			<view class="formBottom" @click="abandonUpdate">放弃修改</view>
		</view>
	</view>
</template>
<script>
	import {
		getVerificationCode,
		mobileRegister
	} from "@/api/landlord.js"
	import {
		getUserInfo,
	} from '@/api/mine.js'
	export default {
		data() {
			return {
				mobile: '', //手机号码
				password: '', //密码
				password_confirm: '', //确认密码
				verification: '', //验证码								
				codeTips: '', //验证码提示信息
			};
		},
		onLoad() {
			this.getUserInfo();
		},
		methods: {
			getUserInfo() {
				getUserInfo().then(res => {
					this.mobile =  res.data.data.userinfo.mobile
				})
			},
			abandonUpdate() {
				uni.navigateBack({
					delta: 1
				})
			},
			codeChange(text) {
				this.codeTips = text;
			},
			//获取验证码
			getVerificationCode() {
				if (!this.mobile) {
					return this.$Toast('请输入您的手机号');
				}
				let that = this
				getVerificationCode({
					mobile: this.mobile,
					event: 'resetpwd'
				}).then(res => {
					if (this.$refs.uCode.canGetCode) {
						uni.showLoading({
							title: '正在获取验证码'
						})
						setTimeout(() => {
							uni.hideLoading();
							this.$refs.uCode.start();
						}, 2000);
					} else {
						this.$Toast('倒计时结束后再发送');
					}
				})
			},
			//当前重置按钮操作
			userRegister() {
				if (!this.mobile) {
					return this.$Toast('请输入您的手机号');
				}
				if (!this.verification) {
					return this.$Toast('请输入短信验证码');
				}
				if (!this.password) {
					return this.$Toast('请输入您的新密码');
				}
				if (!this.password_confirm) {
					return this.$Toast('请输入再次您的新密码');
				}
				mobileRegister({
					mobile: this.mobile,
					password: this.password,
					password_confirm: this.password_confirm,
					captcha: this.verification
				}).then(res => {
					//注册成功
					this.$Tips({
						title: '重置成功'
					}, {
						tab: 3,
						url: '1'
					})
				})
			},
		}
	};
</script>
<style scoped lang="scss">
	.pageBg {
		width: 100%;
		height: 100vh;
		object-fit: cover;
		position: absolute;
		top: 0;
		left: 0;
		z-index: -1;
	}

	.registerPage {
		position: relative;
		padding: 0 32rpx;
		min-height: 100vh;

		.title {
			padding-top: 168rpx;
			font-size: 48rpx;
			letter-spacing: 4rpx;
		}

		.tips {
			padding-top: 12rpx;
			font-size: 26rpx;
			color: #767980;
		}

		.formBottom {
			text-align: center;
			font-size: 26rpx;
			color: #FE4F04;
			margin-top: 20rpx;
		}

		.loginForm {
			margin-top: 96rpx;
			// background: #fff;
			// padding: 50rpx;
			// border-radius: 20rpx;

			.loginTitle {
				text-align: center;
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
				padding-bottom: 68rpx;
			}

			.input {
				padding: 28rpx 48rpx;
				box-sizing: border-box;
				height: 100rpx;
				background: #ffffff;
				box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0, 149, 248, 0.05);
				border-radius: 50rpx 50rpx 50rpx 50rpx;
				margin-bottom: 32rpx;
				display: flex;
				align-items: center;
				overflow: hidden;

				.input-label {
					width: 140rpx;
					font-weight: 600;
					font-size: 30rpx;
					color: #222222;
				}

				.text {
					color: #FE4F04;
				}
			}

			.captchaImage {
				width: 200rpx;
				height: 88rpx;
			}

			.loginButton {
				margin-top: 176rpx;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				background-color: #FE4F04;
				color: #ffffff;
				border-radius: 44rpx;
			}
		}
	}
</style>